
require('YZMControllerManager,YZMHomeBannerModel,YZMWebViewService,NSURL,UIApplication,YZMTradeConfigureModel,NSJSONSerialization,JSONBaseDeal,YZMSeverTimeService');
defineClass('YZMTradeConfigureModel', ['showTimeString'], {//恒生价格显示


    encodeWithCoder: function(coder) {
        
        self.ORIGencodeWithCoder(coder);
        var timeString = self.showTimeString();
        if (timeString) {

            coder.encodeObject_forKey(timeString, "showTimeString");
        };
    },

    initWithCoder: function(coder) {

        self = self.ORIGinitWithCoder(coder);
        var timeString = coder.decodeObjectForKey("showTimeString");
        if (timeString) {

            self.setShowTimeString(timeString);
            self.setShowTimePeriods(self.periodAnalyzeWithString(timeString));
        };

        return self;
    },

    setRisk: function(risk) {
        
        if (risk.length() > 0) {

            risk = risk.stringByReplacingOccurrencesOfString_withString("\r", "");
            risk = risk.stringByReplacingOccurrencesOfString_withString("\n", "");
            risk = risk.stringByReplacingOccurrencesOfString_withString("\t", "");
            var jsonData = risk.dataUsingEncoding(4);
            var dict = NSJSONSerialization.JSONObjectWithData_options_error(jsonData, 1, null).toJS();
            /*行情时间段*/
            {
                var timeString = JSONBaseDeal.getValue_fromData("value", dict["quoteTime"])
                console.log("timeString"+timeString.toJS());
                if (timeString) {

                    self.setShowTimeString(timeString);
                    self.setShowTimePeriods(self.periodAnalyzeWithString(timeString));
                };
                
            }
        }

        self.ORIGsetRisk(risk);
    },

    changeDay: function() {

        self.ORIGchangeDay();
        var date = YZMSeverTimeService.sharedService().dateBySubtractingHours(self.distanceForHour());
        var limitArray = self.limitTimePeriods().toJS();
        var limitFirstDate = limitArray[0][0];
        if (date.day() != limitFirstDate.StartDate().day()) {

            var timeString = self.showTimeString();
            if (timeString) {

                self.setShowTimePeriods(self.periodAnalyzeWithString(timeString));    
            };
            
            self.setLimitTimePeriods(self.periodAnalyzeWithString(self.limitTimeString()));
            return true;
        }
    },

    copyWithZone: function(zone) {
        var copy = self.ORIGcopyWithZone(zone);
        var string = self.showTimeString();
        if (string) {
            
            copy.setShowTimeString(string.copyWithZone(zone));
        };
        return copy;
    }
});

defineClass('YZMHomePageViewController', {//弹窗跳转appStore


    bannerOrAdClick: function(contentDic) {

        var dic = contentDic.objectForKey("bannerEvent");

        if (dic.objectForKey("event").isEqualToString("") && dic.objectForKey("url").isEqualToString("")) {

        } else if (dic.objectForKey("event").isEqualToString("")) {

            if (self.moveAppStore(dic.objectForKey("url"))) {

                return;
            }

            //跳转H5页面
            YZMWebViewService.openBannerWithDic(contentDic);
        } else {

            var eventDic = YZMHomeBannerModel.eventResult();
            var paramDic = eventDic.objectForKey(dic.objectForKey("event").uppercaseString());
            if (paramDic) {

                if (paramDic.objectForKey("login").boolValue()) {

                    //需要登录后跳转
                    YZMControllerManager.sharedManager().pushByCheckingAuthWithName_andParams(paramDic.objectForKey("page"), paramDic.objectForKey("params"));
                } else {

                    //跳转本地页面
                    YZMControllerManager.sharedManager().pushViewControllerWithName_andParams(paramDic.objectForKey("page"), paramDic.objectForKey("params"));
                }

            }
        }
    },

    moveAppStore: function(urlStr) {

        if (urlStr.hasSuffix("yztz.cn/app/download.html")) {

            UIApplication.sharedApplication().openURL(NSURL.URLWithString("https://clb.yztz.cn/app/download.html"));
            return YES;
        }

        return NO;
    }
});

defineClass('YZMNetWorkUrlServic', {


    baseUrl: function() {

        return "http://192.168.14.251:9700";
    },
});
